<template>
  <div id="app">
    <ul>
      <el-button @click="Login" >Login</el-button>
<!--      <el-button @click="Regist">Regist</el-button>-->
      <el-button @click="unshow">进入首页</el-button>
      <!--      <router-view></router-view>-->
    </ul>
  </div>
</template>

<script>
import AppIndex from './Home/AppIndex'
import router from '../router'

export default {
  name: 'homePage',
  components: {
    AppIndex
  },
  data: function () {
    return {
      ifshow: true
    }
  },
  methods: {
    Login () {
      router.push({path: '/login'})
    },
    Regist () {
      router.push({path: '/regist'})
    },
    unshow () {
      this.$axios.get('/user/judgeRole')
        .then(res => {
          if (res.data.status === 100) { // 100可换\
            console.log(res.data)
            router.replace('/index')
          }
        }).catch(err => {
          console.log(err)
          alert('请重新登录')
          this.$router.replace('/login')
        })
      // router.replace('/index')
    }
  },
  created () {
    if (localStorage.getItem('token')) {
      router.push({path: '/index'})
    } else {
      router.push({path: '/login'})
    }
  }
}
</script>

<style scoped>

</style>
